import 'package:example/pages/appbar_title_page.dart';
import 'package:example/pages/avatar_page.dart';
import 'package:example/pages/badge_page.dart';
import 'package:example/pages/button_page.dart';
import 'package:example/pages/empty_page.dart';
import 'package:example/pages/hints_action_empty_page.dart';
import 'package:example/pages/hints_empty_page.dart';
import 'package:example/pages/image_hints_empty_page.dart';
import 'package:example/pages/list_page.dart';
import 'package:example/pages/loading_empty_page.dart';
import 'package:example/pages/static_list_page.dart';
import 'package:example/pages/toast_page.dart';
import 'package:flutter/material.dart';
import 'package:fluttertenroadui/widgets/toast.dart';

import 'about_page.dart';
import 'home_page.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {  
    TLToastDefaults _defaults = TLToastDefaults();
    return MaterialApp(
      title: 'Flutter Demo',
      themeMode: ThemeMode.light,
      theme: ThemeData(
        // This is the theme of your application.
        //
        // Try running your application with "flutter run". You'll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to Colors.green and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or simply save your changes to "hot reload" in a Flutter IDE).
        // Notice that the counter didn't reset back to zero; the application
        // is not restarted.
        primarySwatch: Colors.blue,
        // This makes the visual density adapt to the platform that you run
        // the app on. For desktop platforms, the controls will be smaller and
        // closer together (more dense) than on mobile platforms.
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      routes: {
        HomeTab.routeName: (context)=>HomeTab(),
        AvatarPage.routeName: (context)=>AvatarPage(),
        BadgePage.routeName: (context)=>BadgePage(),
        ButtonPage.routeName: (context)=>ButtonPage(),
        EmptyPage.routeName: (context)=>EmptyPage(),
        LoadingEmptyPage.routeName: (context)=>LoadingEmptyPage(),
        HintsEmptyPage.routeName: (context)=>HintsEmptyPage(),
        HintsActionEmptyPage.routeName: (context)=>HintsActionEmptyPage(),
        ImageHintsEmptyPage.routeName: (context)=>ImageHintsEmptyPage(),
        ListPage.routeName: (context)=>ListPage(),
        StaticListViewPage.routeName: (context)=>StaticListViewPage(),
        AppBarPage.routeName: (context)=>AppBarPage(),
        ToastPage.routeName: (context)=>ToastPage(),
      },
      builder: (context, child) {
        return TLToastProvider(
          defaults: _defaults,
          child: Directionality(
            textDirection: TextDirection.ltr, 
            child: child),
        );
      },
    );
  }
}

class HomeTab extends StatefulWidget {
  static const String routeName = '/';
  HomeTab({Key key, this.title}) : super(key: key);

  // This widget is the home page of your application. It is stateful, meaning
  // that it has a State object (defined below) that contains fields that affect
  // how it looks.

  // This class is the configuration for the state. It holds the values (in this
  // case the title) provided by the parent (in this case the App widget) and
  // used by the build method of the State. Fields in a Widget subclass are
  // always marked "final".

  final String title;

  @override
  _HomeTabState createState() => _HomeTabState();
}

class _HomeTabState extends State<HomeTab> {
  int _currentIndex = 0;
  List pages = [HomePage(), AboutPage()];

  @override
  Widget build(BuildContext context) {
    // This method is rerun every time setState is called, for instance as done
    // by the _incrementCounter method above.
    //
    // The Flutter framework has been optimized to make rerunning build methods
    // fast, so that you can just rebuild anything that needs updating rather
    // than having to individually change instances of widgets.
    return Scaffold(
        body: pages[_currentIndex],
        bottomNavigationBar:  BottomNavigationBar(
          items: <BottomNavigationBarItem>[
            BottomNavigationBarItem(
              icon: Icon(Icons.apps),
              title: Text("Widget"),
            ),
            BottomNavigationBarItem(
              icon: Icon(Icons.info_outline),
              title: Text("about"),
            )
          ],
          currentIndex: _currentIndex,
          onTap: (index) => setState(()=>_currentIndex = index),
        ),
    );
  }
}
